using System;
using System.Data;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for DropDownListHelper
/// </summary>
public partial class ControlHelper
{
    public void FillDataTableToDropDownList(
    DropDownList dropDownList,
    string displayMember,
    string valueMember,
    string selectedValue)
    {

        DataTable dataTable =
        sqlServerProvider.GetDataTable();
        if (dataTable != null)
        {
            dropDownList.DataSource = dataTable;
            dropDownList.DataTextField = displayMember;
            dropDownList.DataValueField = valueMember;
        }
        else
            dropDownList.DataSource = null;
        dropDownList.DataBind();
        if (selectedValue != "")
            dropDownList.SelectedValue = selectedValue;

    }
    public void FillDataTableToDropDownList(
    DropDownList dropDownList,
    string firstDisplayMember,
    string firstValueMember,
    string displayMember,
    string valueMember,
    string selectedValue)
    {


        DataTable dataTable =
        sqlServerProvider.GetDataTable();

        if (dataTable != null)
        {
            if (firstDisplayMember != "")
            {
                DataRow dataRow = dataTable.NewRow();
                dataRow[0] = firstDisplayMember;
                dataRow[1] = firstValueMember;
                dataTable.Rows.InsertAt(dataRow, 0);
            }
            dropDownList.DataTextField = displayMember;
            dropDownList.DataValueField = valueMember;
            dropDownList.DataSource = dataTable;
            dropDownList.DataBind();
            if (selectedValue != "")
                dropDownList.SelectedValue = selectedValue;
        }
        else
        {
            dropDownList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }


    }
    void FillStringToDropDownList(
    DropDownList dropDownList,
    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            dropDownList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        string[] valueCollection =
        sqlServerProvider.GetStrings();
        for (int i = 0; i < valueCollection.Length; i++)
        {
            dropDownList.Items.Add(
            valueCollection[i]);
        }

    }
    public void FillArrayListToDropDownList(
    DropDownList dropDownList,
    string firstDisplayMember,
    string firstValueMember,
    string selectedValue)
    {


        ArrayList arrayList =
        sqlServerProvider.GetArrayList();
        if (arrayList.Count != 0)
        {
            FillArrayListToDropDownList(
            dropDownList, arrayList,
            firstDisplayMember, firstValueMember);
            if (selectedValue != "")
                dropDownList.SelectedValue =
                selectedValue;
        }


    }
    void FillArrayListToDropDownList(
    DropDownList dropDownList,
    ArrayList arrayList,
    string firstDisplayMember,
    string firstValueMember)
    {
        if (firstDisplayMember != "")
        {
            dropDownList.Items.Add(
            new ListItem(firstDisplayMember,
            firstValueMember));
        }
        for (int i = 0; i < arrayList.Count; i++)
        {
            string[] item = (
            string[])arrayList[i];
            dropDownList.Items.Add(
            new ListItem(item[1], item[0]));
        }

    }
}
